package com.pan.controller.Managers;

import com.pan.aop.BusinessType;
import com.pan.aop.MyLog;
import com.pan.controller.tools.Methods;
import com.pan.controller.tools.R1;
import com.pan.service.IManagerService;
import com.pan.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/salarymanagerchange")
@Tag(name = "SalaryManagerController",description = "管理员修改薪水")
public class SalaryManagerController {
    @Autowired
    private IManagerService managerService;
    @Autowired
    private IUserService userService;

    Methods methods = new Methods();

    //管理员修改薪水
    @Operation(summary = "管理员修改薪水",description = "管理员可以修改任何人的薪水")
    @PutMapping
    @MyLog(title = "管理员修改薪水",optParam = "#{id},#{salary}",businessType = BusinessType.UPDATE)
    public R1 changeSalary(@Parameter(description = "编号",required = true,example = "1")@RequestParam Integer id,
                           @Parameter(description = "新的薪水",required = true,example = "12000")@RequestParam Integer salary,
                           HttpServletRequest request) {
        //检查用户权限
        if (methods.isManager(request,userService)){
            return new R1(managerService.changeSalary(id,salary));
        }
        return new R1(false,"权限不足");
    }
}
